package com.dosen.api.thought.core.service.entity;

import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.annotation.*;
import com.dosen.api.base.common.asserts.AssertNP;
import com.dosen.api.base.common.utils.information.JSONUtil;
import com.dosen.api.thought.common.model.valobj.ThoughtIndices;
import com.dosen.api.thought.common.model.valobj.ThoughtMethod;
import com.dosen.api.thought.common.model.valobj.ThoughtPractice;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * @author zhanggc
 * @email zhangguangcheng@beyondcent.com
 * @date 2023-01-24 15:05:19
 */
@Data
@TableName("dosen_search_thought")
@Accessors(chain = true)
public class SearchThoughtEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 记录名称
     */
    private String name;
    /**
     * 记录别名
     */
    private String alias;
    /**
     * 记录描述
     */
    private String description;
    /**
     * 外部存储索引对象
     *
     * @see com.dosen.api.thought.common.model.valobj.ThoughtIndices
     */
    private String indices;
    /**
     * 人工补充特征或标签用于检索 xxx;xxx;xxx;xxx;xxx
     */
    private String dosenSearch;
    /**
     * 思想内容类型：文本文件【textFile】，音频文件【audioFile】，视频文件【videoFile】，字符串【string】等
     */
    private Integer contentType;
    /**
     * 前端展示
     */
    @TableField(exist = false)
    private String contentTypeShow;
    /**
     * 思想内容所在位置对象: 本表【Local】，redis【Remote】，es【Remote】，
     */
    private String location;
    /**
     * 内容较少可直接存在表中: location=Local时
     * 密码，口令等小内容
     */
    private String content;
    /**
     * 方法对象
     *
     * @see com.dosen.api.thought.common.model.valobj.ThoughtMethod
     */
    private String method;
    /**
     * 实践对象
     *
     * @see com.dosen.api.thought.common.model.valobj.ThoughtPractice
     */
    private String practice;
    /**
     * 权重：查询，更新有结果后权重+1
     */
    private Long weight;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isDeleted;
    /**
     *
     */
    @Version
    @TableField(fill = FieldFill.INSERT)
    private Long version;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT)
    private String createdBy;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT)
    private Date createdTime;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String updatedBy;
    /**
     *
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updatedTime;


    /**
     * @return
     */
    public ThoughtIndices thoughtIndices() {
        if (!AssertNP.legalParams(indices)) {
            return new ThoughtIndices();
        }
        return JSONUtil.getT(indices, new TypeReference<ThoughtIndices>() {
        });
    }

    /**
     * @return
     */
    public ThoughtMethod thoughtMethod() {
        if (!AssertNP.legalParams(method)) {
            return new ThoughtMethod();
        }
        return JSONUtil.getT(method, new TypeReference<ThoughtMethod>() {
        });
    }

    /**
     * @return
     */
    public ThoughtPractice thoughtPractice() {
        if (!AssertNP.legalParams(practice)) {
            return new ThoughtPractice();
        }
        return JSONUtil.getT(practice, new TypeReference<ThoughtPractice>() {
        });
    }

    public static void main(String[] args) {
        String json = "{\n" +
                "    \"providerId\": \"11\",\n" +
                "    \"methodName\": \"QueryVmExecute\",\n" +
                "    \"opParams\": {\n" +
                "        \"vendorCategory\": \"COMPUTE\"\n" +
                "    }\n" +
                "}";

        DemoEntity demoEntity = JSONUtil.getT(json, new TypeReference<DemoEntity>() {
        });

        Map<String, String> opParams = demoEntity.getOpParams();
        System.out.println("opParams =\n" + opParams);
    }
}
